<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"      
      xmlns:sec="http://www.springframework.org/security/tags"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:pf="http://primefaces.org/ui">
    <h:body>
        <ui:composition>
            <script>
                
                function toggleUserInfoPanel() {
                    $("#userInfoPanel").slideToggle(100, function(){});
                };
                
                $(document).ready(function() {
                    $("#userInfoButton").click(toggleUserInfoPanel
                    );
                });
            </script>
            <div>
            <h:form id="menuForm" prependId="false"> 
                <pf:toolbar>
                    <pf:toolbarGroup align="left">
                        <pf:commandButton value="Home" action="/index.xhtml?faces-redirect=true" />
                        <pf:menuButton value="Tests">
                            <pf:menuitem value="Contactbook" url="/pages/tests/contactbook.xhtml" />
                            <pf:menuitem value="GC synchronization" url="/pages/admin/gcSynchronization.xhtml" />                                                        
                            <pf:menuitem value="Dictionary" url="/pages/admin/dictionary.xhtml" />
                        </pf:menuButton>
                    </pf:toolbarGroup>
                    <pf:toolbarGroup align="right">
                         <c:choose>
                            <c:when test="#{not empty request.userPrincipal}">
                                <pf:commandButton value="Logout" actionListener="#{loginBean.logout}"/>
                            </c:when>
                            <c:otherwise>
                                <pf:commandButton value="Login" action="/login.xhtml?faces-redirect=true" />
                            </c:otherwise>      
                        </c:choose>
                    </pf:toolbarGroup>
                </pf:toolbar>
                <!--
                <pf:menubar>
 
                    <pf:menuitem value="Home" url="/index.xhtml" />
                    <pf:submenu label="Tests">
                            <pf:menuitem value="contactbook" url="/pages/tests/contactbook.xhtml" />
                            <pf:menuitem value="GC synchronization" url="/pages/admin/gcSynchronization.xhtml" />                            
                    </pf:submenu>
                    <pf:menuitem value="logout" style="right: 0px; " />
                    <pf:menu
                </pf:menubar>
                -->
            </h:form>
                <pf:growl id="globalGrowl" globalOnly="true" showDetail="true" autoUpdate="true" /> 
            </div>
            <ui:remove>
            <div class="userInfoButtonWrapper">
                <div id="userInfoButton">
                    <div style="margin: 0px; padding: 0px; display: inline; top:0px; float: left;">
                        <c:choose>
                            <c:when test="#{not empty request.userPrincipal}">
                                Logged as: <b>#{request.userPrincipal.name}</b>
                            </c:when>
                            <c:otherwise>
                                Not logged in
                            </c:otherwise>      
                        </c:choose>
                    </div>
                    &nbsp;&nbsp;<img style="display: inline;" src="images/gear_18x18.png" />
                </div>
                <div id="userInfoPanel">
                    <c:choose>
                        <c:when test="#{ not empty request.userPrincipal}">
                            <table style="width: 98%;">

                            <tr>
                                <td>
                                    User name:
                                </td>
                                <td>
                                    #{request.userPrincipal.name}
                                </td>
                            </tr>
                            <tr><td>Roles: </td></tr>
                            <tr>
                                <td>
                                    <c:forEach items="#{loginBean.roles}" var="item">
                                        &nbsp;&nbsp;#{item.authority}<br />
                                    </c:forEach>   
                                </td>                                    
                            </tr>
                            <tr>
                                <td colspan="2"><hr /></td>
                            </tr>
                            <tr>
                                <td colspan="2" style="text-align: right; ">
                                    <h:form>
                                        <h:commandLink class="logoutLink" actionListener="#{loginBean.logout}" value="Logout" />
                                    </h:form>
                                </td>
                            </tr>
                        </table>                                     
                        </c:when>
                        <c:otherwise>                                    
                            <h:form id="panelLoginForm" >
                                <h:panelGrid columns="1">
                                    <h:outputLabel value="User Name" for="j_username"/>
                                    <h:inputText id="j_username"
                                                value="#{loginBean.username}" size="24"
                                                maxlength="80" required="true"/>
                                    <h:outputLabel value="Password" for="j_password"/>
                                    <h:inputSecret id="j_password"
                                                    value="#{loginBean.password}" size="24"
                                                    maxlength="80" required="true"/>
                                </h:panelGrid>
                                <h:commandButton actionListener="#{loginBean.login}" value="Login"/>

                                <h:messages style="color: red;"/>
                            </h:form>
                        </c:otherwise>
                    </c:choose>
                    <div style="width: 100%; 
                                height: 10px; 
                                text-align: center;
                                border-top: 1px solid dodgerblue; 
                                margin-top: 4px;
                                cursor: pointer;"
                                onclick="toggleUserInfoPanel()">
                        ^^^
                    </div> 
                </div>
            </div>
            </ui:remove>
        </ui:composition>  
    </h:body>
</html>

